package com.ewanghuiju.app.ui.pintuan.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.pintuan.PintuanHomeContract;
import com.ewanghuiju.app.model.bean.response.PintuanShopListResponBean;
import com.ewanghuiju.app.presenter.pintuan.PintuanHomePresenter;
import com.ewanghuiju.app.test.bean.MyPageGridBean;
import com.ewanghuiju.app.test.bean.PintuanHomeBannerBean;
import com.ewanghuiju.app.test.bean.TestBean;
import com.ewanghuiju.app.ui.pintuan.adapter.PintuanShopListAdapter;
import com.ewanghuiju.app.util.ToastUtil;
import com.gyf.immersionbar.ImmersionBar;
import com.stx.xhb.androidx.XBanner;
import com.wihaohao.PageGridView;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * @author sj  qq:751943509
 * @class 拼团首页
 * @time 2020/2/19
 */
public class PintuanHomeActivity extends BaseActivity<PintuanHomePresenter> implements PintuanHomeContract.View {
    @BindView(R.id.mIv)
    ImageView mIv;
    @BindView(R.id.top_view)
    View topView;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.et_search)
    EditText etSearch;
    @BindView(R.id.go_search)
    LinearLayout goSearch;
    @BindView(R.id.xbanner)
    XBanner xbanner;
    @BindView(R.id.frame)
    LinearLayout frame;
    @BindView(R.id.pageView)
    PageGridView<MyPageGridBean> pageView;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;


    private List<PintuanHomeBannerBean> bannerList = new ArrayList<>();

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_pintuan_home;
    }

    @Override
    protected void initEventAndData() {
        initBanner();
        initItem();
        intShopList();
    }

    /**
     * 加载banner
     */
    public void initBanner() {
        PintuanHomeBannerBean bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.pintuan_home_banner);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.pintuan_home_banner);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.pintuan_home_banner);
        bannerList.add(bean);
        xbanner.setBannerData(bannerList);
        //加载广告图片
        xbanner.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
//                ImageView imageView = (ImageView) view;
//                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
//                GlideRoundTransform glideRoundTransform = new GlideRoundTransform(SampleApplicationLike.getInstance(), 10);
//                Glide.with(SampleApplicationLike.getInstance())
//                        .load(bannerList.get(position).getCreateImgUrl())
//                        .placeholder(R.mipmap.default_big)
//                        .bitmapTransform(glideRoundTransform)
//                        .diskCacheStrategy(DiskCacheStrategy.NONE) // 不使用磁盘缓存
//                        .into(imageView);
                Glide.with(mContext).load(R.mipmap.pintuan_home_banner).into((ImageView) view);
            }
        });
    }
    /**
     * 图标分类
     */
    private void initItem() {
        List<MyPageGridBean> classifyList = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            MyPageGridBean bean = new MyPageGridBean();
            bean.setTitle("淘宝");
            bean.setImg("");
            classifyList.add(bean);
        }
        pageView.setData(classifyList);
        pageView.setOnItemClickListener(new PageGridView.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                ToastUtil.show("" + position);
            }
        });
    }

    /**
     *  加载商品列表
     */
    private void intShopList() {
        List<PintuanShopListResponBean> mList = TestBean.getPintuanShopListResponBeanList();
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        PintuanShopListAdapter  pintuanShopListAdapter = new PintuanShopListAdapter(R.layout.item_pintuan_shop);
        recyclerView.setAdapter(pintuanShopListAdapter);
        pintuanShopListAdapter.addData(mList);
        pintuanShopListAdapter.notifyDataSetChanged();
    }
    @Override
    public void showContent(String list) {

    }

    @Override
    public void showMoreContent(String list) {

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).statusBarView(R.id.top_view)
//                .navigationBarColor(R.color.colorPrimary)
//                .fullScreen(true)
//                .addTag("PintuanHomeActivity")
                .init();
    }
}
